package com.edie.customview.modular.mymvp;


import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.edie.customview.R;
import com.edie.customview.basemvp.BaseMvpFragment;

/**
 * - @Description:  demo 对应主页
 * - @Author:  edie
 * - @Time:  2018/8/10 下午6:10
 */
public class HomeFragment extends BaseMvpFragment<MyMvpContract.IMyMvpPresenter> implements MyMvpContract.IMyMvpView, View.OnClickListener {

    private EditText mInputEt;
    private Button mQueryBtn;
    private TextView mResultTv;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        initView(view);
        return view;
    }


    @Override
    protected MyMvpContract.IMyMvpPresenter initPresenter() {
        return new MyMvpPresenterImpl(this);
    }

    @Override
    public void showMsg(String msg) {
        mResultTv.setText(msg);
    }

    private void initView(View view) {
        mInputEt = (EditText) view.findViewById(R.id.input_et);
        mQueryBtn = (Button) view.findViewById(R.id.query_btn);
        mResultTv = (TextView) view.findViewById(R.id.result_tv);

        mQueryBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.query_btn:
                String et = mInputEt.getText().toString().trim();
                if (TextUtils.isEmpty(et)) {
                    Toast.makeText(getContext(), "不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                mPresenter.loadMsg(et);
                break;
        }
    }

}
